import api from "../../api/login.js";
import {
  setLoginInfo,
  removeLoginInfo
} from '../../utils/loginInfo.js'

Page({
  data: {
    username: '',
    password: '',
    socialCodeValid: true
  },
  onLoad() {
    removeLoginInfo()
  },
  onChange(e) {
    const ele = e.currentTarget.dataset.ele
    this.setData({
      [ele]: e.detail
    })
  },
  async onLogin() {
    const res = await api.login(this.data)
    if (res.code === 0) {
      await setLoginInfo(res.data) // 设置登录信息
      wx.switchTab({
        url: '/pages/index/index',
      })
    } else {
      wx.showModal({
        content: res.msg,
        confirmText: '我知道',
        showCancel: false,
      })
    }
  },
  onPasswork() {
    wx.navigateTo({
      url: '/pages/passwork/index',
    })
  }
})